package zxj.spay.modular.data.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import zxj.spay.base.Result;
import zxj.spay.entity.Stream;
import zxj.spay.entity.Type;
import zxj.spay.entity.User;
import zxj.spay.modular.data.dao.StreamDao;
import zxj.spay.modular.data.dao.TypeDao;
import zxj.spay.modular.data.service.DataService;

/**
 * 添加数据
 * @author Administrator
 *
 */
@Service
public class DataServiceImpl implements DataService{
	@Resource
	private TypeDao typeDao;
	@Resource
	private StreamDao streamDao;

	@Override
	public Result addType(Type type,int user_id) {
		//判断此类型用户是否已经存在
		Type dbt = typeDao.getByUserIdAndTypeName(user_id,type.getTypeName());
		if(dbt != null){
			return new Result(Result.WARN,"此类型已经存在，无法重复添加");
		}
		User user = new User();
		user.setId(user_id);
		type.setUser(user);
		type.setCreateTime(new Date());
		typeDao.save(type);
		return new Result(Result.SUCCESS);
	}

	@Override
	public List<Type> getTypeByStatus(int status, int user_id) {
		List<Type> types = typeDao.getByStatusAndUserId(status,user_id);
		System.out.println(types.size());
		return types;
	}

	@Override
	public Result saveStream(Stream stream) {
		stream.setCreateTime(new Date());
		streamDao.save(stream);
		return new Result(Result.SUCCESS);
	}

}
